import request from '@/api/config/request'
import { ApiResponse } from './type'

export interface TagData {
  id: number,
  name: string,
  createdAt?: string
}
export interface TagList {
  tag: TagData[];
  total: number;
}
export interface Params {
  name?: ''
  pageNum: number;
  pageSize: number;
}
export interface TagAllList {
  id:number,
  name:string
}

// 获取全部类目分页
export const getTag = (data: Params): Promise<ApiResponse<TagList>> => {
  return request.post('/tag/find', data)
}
// 获取全部类目不分页
export const getAllTag = (): Promise<ApiResponse<TagAllList[]>> => {
  return request.post('/tag/findAll')
}

// 添加新类目 Omit 排除id
export const addNewTag = (data: Omit<TagData, 'id'>): Promise<ApiResponse<null>> => {
  return request.post(
    '/tag/add',
    data
  )
}

// 删除指定菜单
export const removeTagByID = (id: number): Promise<ApiResponse<null>> => {
  return request.delete(`/tag/${id}`)
}

// 更新指定菜单
export const updateTagByID = (id: number, data: TagData): Promise<ApiResponse<null>> => {
  return request.patch(`/tag/${id}`, data)
}
